#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include <QMainWindow>
#include <QWidget>
#include <QMap>
#include <QPointer>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMimeData>
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QFontComboBox)
QT_FORWARD_DECLARE_CLASS(QTextEdit)
QT_FORWARD_DECLARE_CLASS(QTextCharFormat)
QT_FORWARD_DECLARE_CLASS(QMenu)

class TextEdit : public QWidget
{
    Q_OBJECT

public:
	TextEdit(QWidget *parent = 0);
	QString fileSave();
	QStringList getAddedImages() const;
	QString getCurrentFileName();
	void setCurrentFileName(const QString &curPath);
	void fileOpen(const QString &curFile);
protected:
	virtual void closeEvent(QCloseEvent *e);
private:
	void setupEditActions();
	void setupTextActions();
	bool load(const QString &f);
private slots:
	void imageOpen();
	void textBold();
	void textUnderline();
	void textItalic();
	void textFamily(const QString &f);
	void textSize(const QString &p);
	void textStyle(int styleIndex);
	void textColor();
	void textAlign(QAction *a);
	void currentCharFormatChanged(const QTextCharFormat &format);
	void cursorPositionChanged();
	void clipboardDataChanged();
private:
    void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
    void fontChanged(const QFont &f);
    void colorChanged(const QColor &c);
    void alignmentChanged(Qt::Alignment a);
    void insertFromMimeData( const QMimeData *);

    QAction
        *actionTextBold,
        *actionTextUnderline,
        *actionTextItalic,
        *actionTextColor,
        *actionAlignLeft,
        *actionAlignCenter,
        *actionAlignRight,
        *actionAlignJustify,
        *actionUndo,
        *actionRedo,
        *actionCut,
        *actionCopy,
        *actionPaste;

    QComboBox *comboStyle;
    QFontComboBox *comboFont;
    QComboBox *comboSize;

    QToolBar *tb;
    QVBoxLayout layout;
    QHBoxLayout toolBar1;
    QHBoxLayout toolBar2;
	QString fileName;
	QString name;
	QString path;
	QTextEdit *textEdit;
	QStringList listAddedImages;
};

#endif
